<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function sayhi(){
            alert("你点击了sayHi按钮")
        }

        window.onload=function (){ //表示页面加载完之后才进行动态绑定，否则btn01对象为null
            var elementById = document.getElementById("btn01");
            elementById.onclick=function (){
                alert("你点击了sayOk按钮")
            }
        }
    </script>
</head>
<body>
<button onclick="sayhi()">sayHi按钮</button>
<button id="btn01">sayOk按钮</button>
</body>
</html>